Class Nur.MNISV3.Service.ScanEvents Extends %RegisteredObject [ Not ProcedureBlock ]
{

/*
module     模块（固定）      "OrderExecute"
motion      动作（固定）      "scan"
entities        实体（回传） "barcode": "0000000598" 登记号 或瓶贴 ; "entity": "patient" 患者 或医嘱order
                       "manual": "0" 是否手动 "scan": "1" 是否扫码 ; "result": "1708" 结果是就诊号
extras      附加参数            "{\""panel\"":\""\"",\""open\"":\""0\"",\""check\"":\""0\"",\""select\"":\""0\"",\""scan\"":\""1\"",\""manual\"":\""0\"",\""single\"":\""1\"",\""multiple\"":\""0\""}"
callback        回调参数（回传）    ""
barcode     条码              "0000000598"
expectance  条码期望类型      ""
behavior 行为: "request" 是请求; "open"或"close"是打开或关闭panels面板 "check"或"uncheck" 是由onCheckOrderV4发起
request  请求名称 "GetOrdersV4" 或"GetOrderTasksV4" 或"GetOrdersV4&GetOrderTasksV4" 或"ExecOrSeeOrderV4"
dialog   对话框  格式固定看CreateDialog方法
toast    通用toast提示(任何请求方法都可添加) toast是系统默认(1.5秒) toast2是自定义的(3秒) toast3是弹框5秒自动消失 toast4是弹框确认
*/
/// **************统一扫码入口**************
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV4("OrderExecute","scan","0000000037","3","20665","8","23","2","{""single"":""1"",""activity"":""UniversalActivity"",""scan"":""0"",""multiple"":"""",""manual"":""0"",""panel"":"""",""open"":""0"",""switch"":""0""}"))
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV4("Tour","scan","0000000689","","3","20665","8","23","2","{""single"":""0"",""flag"":"""",""tab"":""/"",""scan"":""0"",""multiple"":""1"",""barcode"":"""",""open"":""0""}")
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV4("Tour","scan","1174||1169||128","","3","20665","8","23","2","{""single"":""0"",""flag"":"""",""tab"":""/"",""scan"":""0"",""multiple"":""1"",""barcode"":"""",""open"":""0""}")
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV4("Tour","scan","DD0001","[{""barcode"":""0000000689"",""entity"":""patient"",""manual"":"""",""result"":""1217"",""scan"":""1""},{""barcode"":""669||76||822"",""entity"":""order"",""manual"":"""",""result"":"""",""scan"":""1""},{""barcode"":""669||76||822"",""entity"":""order"",""manual"":"""",""result"":"""",""scan"":""1""},{""barcode"":""0000000689"",""entity"":""patient"",""manual"":"""",""result"":""1217"",""scan"":""1""}]","3","20665","8","23","2","{""single"":""0"",""flag"":""1"",""tab"":""/"",""scan"":""0"",""multiple"":""1"",""barcode"":"""",""open"":""1""}")
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV4("Tour","scan","0010412334353","[{""barcode"":""P0065V00"",""entity"":""blood"",""manual"":null,""result"":"""",""scan"":""1""}]","3","20665","8","23","2","{""single"":""0"",""flag"":"""",""tab"":""DHCNurGradeTourPda/"",""scan"":""0"",""multiple"":""1"",""barcode"":""0010412334353"",""open"":""0""}")
ClassMethod GetScanInfoV4(module, motion, barcode, entities, wardId, userId, locId, groupId, hospitalId, extras)
{
    n (module,motion,barcode,entities,wardId,userId,locId,groupId,hospitalId,extras)
    s $zt="errGetScanInfoV4"
    s ^GRS("GetScanInfoV4",1,barcode_"-")=$lb(module,motion,barcode,entities,wardId,userId,locId,groupId,hospitalId,extras)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    s barcode=$replace(barcode,$c(0),"")
    s barcodeFlag=##class(Nur.MNISV3.Service.Barcode).GetBarcodeFlag(barcode,"","",wardId,.outputBarcode,.barcodeMessage,.ordFlag)
    w barcodeFlag,!
    s patInfo=##class(%ArrayOfDataTypes).%New()
    s userInfo=##class(%ArrayOfDataTypes).%New()
    s orders=##class(%ListOfDataTypes).%New()
    s changePat="" 
    //先处理entities
    i entities="" { //空 创建一个entities
        s newEntities=##class(%ListOfDataTypes).%New()
    }else {
        // 移除重复扫码的
        s newEntities=##class(Nur.MNISV3.Common.Utils).RemoveEntitiesByBarCode(entities,barcode)
        // 获取entities中就诊号
        s barCode1=##class(Nur.MNISV3.Common.Utils).GetBarcodeByEntities(newEntities,"patient")
        s regNoNT=$p(barCode1,"^",1)
    }
    //创建patient 并添加
    i barcodeFlag="PAT" { 
        w $g(regNoNT),!
        i ($g(regNoNT)'="") {// 已经存在患者腕带---先移除
            i barcode'=regNoNT s changePat="1"
            s newEntities=##class(Nur.MNISV3.Common.Utils).RemoveEntitiesByBarCode(newEntities,regNoNT,"patient")
        }
        s getPatAdmValue=##class(Nur.MNISV3.Service.Patient).GetPatAdm(barcode)
        s episodeId=$P(getPatAdmValue,"^",1)
        s obj=..CreateObject("barcode,entity,result,scan",barcode,"patient",episodeId,"1")
        d newEntities.Insert(obj)
    }
    // "^LAB^MED^INF^INJ^PIS^"
    i barcodeFlag="INF" {
        s obj=..CreateObject("barcode,entity,result,scan",barcode,"order","","1")
        d newEntities.Insert(obj)
    }
    
    // 获取患者信息
    i barcodeFlag="PAT" {
        s barcode=outputBarcode 
        s patinfoObj=##class(Nur.MNISV3.Common.JSON).Decode(##class(Nur.MNISV3.Service.Patient).GetPatWristInfo(barcode,wardId))
        s status=patinfoObj.GetAt("status")
        s msg=patinfoObj.GetAt("msg")
        s msgcode=patinfoObj.GetAt("msgcode")
        i status="0" s patInfo=patinfoObj.GetAt("patInfo")
    }
    // 获取用户信息
    i barcodeFlag="SSU" {
        s userId=$o(^SSU("SSUSR",0,"SSUSR_Initials",$$ALPHAUP^SSUTIL4(barcode),""))
        i userId'="" s userCode=$p($g(^SSU("SSUSR",userId)),"^",1)
        i userId="" s msg="无法识别的工牌!",status="-1",msgcode="100121"
        d userInfo.SetAt($g(userId),"userId")
        d userInfo.SetAt($g(usname),"userName")
        d userInfo.SetAt($g(barcode),"userCode")
    }
    // 其他的情况
    i barcodeFlag="" {
        //地点巡视
        i barcode["DD" {
            s barcodeFlag="SPOT"
            d newEntities.Insert(..CreateObject("barcode,entity,result,scan",barcode,"spot","","1"))
        }
        // 判断输血--"BLOODPRODUCT" 血制品  "BLOODBAG" 血袋
        i barcodeFlag="" {
            s flag=##class(Nur.MNISV3.Service.Blood).GetBarcodeFlag(barcode)
            i (flag="BLOODPRODUCT")||(flag="BLOODBAG") {
               s barcodeFlag="BLOOD"
               d newEntities.Insert(..CreateObject("barcode,entity,result,scan",barcode,"blood","","1"))
            }
        }
    }
    /// ========================上面是公共的扫码处理, 下面是对应功能模块======================
    i module="Tour" { //巡视
        //重点参数: 引用json ,barcodeFlag类型 ,newEntities对象
        s tmpEntities=##class(Nur.MNISV3.Common.JSON).Encode(newEntities) //方便传参
        w "巡视-"_tmpEntities,!
        s tJson=##class(Nur.MNISV3.Service.TourRec).GetScanTourInfo(barcodeFlag,motion, barcode, tmpEntities, wardId, userId, locId, groupId, hospitalId, extras)
        s tStatus=tJson.GetAt("status")
        s tOrders=tJson.GetAt("orders")
        i tOrders'="" s orders=tOrders
        i tJson.GetAt("toast2")'="" s toast2=tJson.GetAt("toast2")
        i tStatus="-1" s Status=tStatus,Msg=tJson.GetAt("msg") //有错误 赋值返回
        s panels=tJson.GetAt("panels")
    }
    // 未识别条码
    i barcodeFlag="" s Msg="未识别的条码!",Status="-1"
    
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    d json.SetAt($g(patInfo),"patInfo")
    d json.SetAt($g(orders),"orders")
    d json.SetAt($g(userInfo),"userInfo")
    d json.SetAt($g(barcodeFlag),"barCodeType")
    d json.SetAt($g(newEntities),"entities")
    d json.SetAt($g(panels),"panels")
    d json.SetAt($g(toast),"toast")
    d json.SetAt($g(toast2),"toast2")
    d json.SetAt($g(toast3),"toast3")
    i $g(tBehavior)'="" d json.SetAt(tBehavior,"behavior")
    i $g(tRequest)'="" d json.SetAt(tRequest,"request")
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
    
errGetScanInfoV4
   s Msg=$ze
   s ^GRS("errGetScanInfoV4")=Msg
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// **************统一操作/执行入口**************
/// module 模块名称 例如:"OrderExecute"
/// motion 动作名称 例如:"execute"
/// button 按钮Id 例如:"seeOrder^A" 处理医嘱
/// entities 扫码对象 例如:"[{""barcode"":""669||25||867"",""entity"":""order"",""manual"":""1"",""result"":""679"",""scan"":""0""},{""barcode"":""669||25||868"",""entity"":""order"",""manual"":""1"",""result"":""679"",""scan"":""0""}]"
/// extras 扩展参数 例如:"{""single"":""1"",""select"":""0"",""activity"":""UniversalActivity"",""scan"":""0"",""multiple"":""0"",""sheet"":""[DefaultSee, DefaultSee]"",""check"":""1"",""manual"":""0"",""panel"":"""",""open"":""0"",""switch"":""0"",""status"":""""}"
/// behavior是行为控制-可以是多个","  ; request是请求那个方法名 例如:"GetOrdersV4" 或 "GetOrdersV4&GetOrderTasksV4"
/// 例如1: behavior="open" 打开面板 "close" 关闭面板 "search" 刷新请求列表-->空即可d json.SetAt("","request")
/// 例如2: behavior="request" 再调用"ExecOrSeeOrderV4"-->需要d json.SetAt("ExecOrSeeOrderV4","request")
/// w ##class(Nur.MNISV3.Service.ScanEvents).ExecOrSeeOrderV4("Tour","save","100","[{""barcode"":""0000000689"",""entity"":""patient"",""manual"":"""",""result"":""1217"",""scan"":""1""}]","3","20665","8","23","2","{""single"":""0"",""flag"":""1"",""tab"":""/"",""scan"":""0"",""multiple"":""1"",""barcode"":"""",""open"":""1""}","{""8||3"":""是"",""8||2"":""10:47"",""8||1"":""2025-08-22"",""8||7"":""污浊"",""8||6"":""俯卧位"",""8||5"":""意识模糊"",""8||4"":""请假""}","","")
ClassMethod ExecOrSeeOrderV4(module, motion, button, entities, wardId, userId, locId, groupId, hospitalId, extras, form, element, callback)
{
    n (module, motion, button, entities, wardId, userId, locId, groupId, hospitalId, extras,form,element,callback)
    s $zt="errExecOrSeeOrderV4"
    s ^GRS("ExecOrSeeOrderV4",userId_"-")=$lb(module, motion, button, entities, wardId, userId, locId, groupId, hospitalId, extras,form,element,callback)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    s patInfo=##class(%ArrayOfDataTypes).%New()
    s userInfo=##class(%ArrayOfDataTypes).%New()
    //先处理entities-空 创建一个entities
    i entities="" {
        s newEntities=##class(%ListOfDataTypes).%New()
        i element'="" { //手动选择医嘱--侧滑撤销
            s elementObj=##class(Nur.MNISV3.Common.JSON).Decode(element) 
            s oeoreId=elementObj.GetAt("value")
            i oeoreId["||" {
                s obj=..CreateObject("barcode,entity,manual,result,scan",oeoreId,"order","1",+^OEORD(+oeoreId),"0")
                d newEntities.Insert(obj)
            }
        }
    }else {
        s newEntities=##class(Nur.MNISV3.Common.JSON).Decode(entities)
    }
    //extras扩展参数
    s extrasObj=##class(Nur.MNISV3.Common.JSON).Decode(extras) 
    /// ========================上面是公共的扫码处理, 下面是对应功能模块======================
    i module="Tour" { //巡视
        //重点参数:引用json , button按钮Id ,form表单录入数据 ,entities对象
        s tmpEntities=##class(Nur.MNISV3.Common.JSON).Encode(newEntities) //方便传参
        s tJson=##class(Nur.MNISV3.Service.TourRec).SaveTour(motion, button, tmpEntities, wardId, userId, locId, groupId, hospitalId, extras,form,element,callback)
        s tStatus=tJson.GetAt("status") // behavior  request
        s tBehavior=tJson.GetAt("behavior")
        s tRequest=tJson.GetAt("request")
        i tStatus="-1" s Status=tStatus,Msg=tJson.GetAt("msg")
    }
    i module="OrderExecute" { //医嘱执行
        //重点参数: button按钮Id ,entities对象, extras扩展参数
        s sheetCode="" // 当前表单code
        i extrasObj.GetAt("sheet")'="" {
            s sheetsList=##class(Nur.MNISV3.Common.JSON).Decode(extrasObj.GetAt("sheet")) 
            s sheetCode=sheetsList.GetAt(1)
        }
        
        s scanFlag=0 // 扫码标志：0-手动执行，1-扫码执行
        s oeoreIdStr="" //医嘱Id串
        
        f idx=newEntities.Count():-1:1 { //倒序循环
            s curObj=newEntities.GetAt(idx)
            s entity=curObj.GetAt("entity")
            s curoeoreId=curObj.GetAt("barcode")
            continue:entity'="order" //过滤'非医嘱'
            continue:curoeoreId=""
            i curObj.GetAt("scan")="1" s scanFlag="1" //扫码标志
            d newEntities.RemoveAt(idx) //移除操作
            //过滤子医嘱
            s oeordID = $o(^OEORD(0,"Adm",+^OEORD(+curoeoreId),0))
            s oeoriSub = $p(curoeoreId,"||",2)
            s ordSeqID = $p($g(^OEORD(oeordID,"I",oeoriSub,11)),"^",39)
            continue:ordSeqID'=""
            
            i oeoreIdStr="" s oeoreIdStr=curoeoreId
            e  s oeoreIdStr=oeoreIdStr_"^"_curoeoreId
        }
        //没有医嘱可执行
        i oeoreIdStr="" q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson("没有医嘱可执行!","100021","-1")
        
        s execStatusCode="" //默认
        //处理或撤销处理 "seeOrder"="A|接受^S|完成^R|拒绝" 
        i (button["seeOrder^")||(button="cancelSeeOrder") {
            i button["^" s execStatusCode=$p(button,"^",2)
            i $g(sheetCode)="" s sheetCode="DefaultSee"
            s sheetSetting=##class(Nur.NIS.Service.OrderExcute.QueryOrder).GetSheetSetting(sheetCode,hospitalId)
            s ^GRS("SeeOrder",userId_"-")=$lb(oeoreIdStr,userId,execStatusCode,"",$g(execDate),$g(execTime),locId,sheetSetting)
            i $g(execStatusCode)'="" s retsult=##class(Nur.NIS.Service.Base.OrderHandle).SeeOrder(oeoreIdStr,userId,execStatusCode,"",$g(execDate),$g(execTime),locId,sheetSetting)
            e  s retsult=##class(Nur.NIS.Service.Base.OrderHandle).CancelSeeOrder(oeoreIdStr,userId,locId,sheetSetting)
            i retsult'="0" s Msg=retsult,Status="-1"
        } else {
            i button="excuteOrder" s execStatusCode="F" //"execOrder"="F|执行"
            i button="cancelOrder" s execStatusCode="C" //"cancelOrder"="C|撤销执行"
            i button="stopExcuteOrder" s execStatusCode="D" //"stopExcuteOrder"="D|停止执行"
            //参数:setSkinTest, oeoreIdStr, execStatusCode, userId, userDeptId, queryTypeCode, execDate, execTime, pcExecReasonDr = "", changeReasonDr = "", groupID = "", auditUser = "", isSttDateTime = "", ordExecExecuteFlag = "N", executeDevice = "PC"
            i $g(execStatusCode)'="" { // 必须有执行状态code
                // 设置执行方式：1-PC，2-PDA手动，3-PDA扫码
                s executeMethod = 1  // 默认PC
                i scanFlag=1 {
                    s executeMethod = 3  // PDA扫码执行
                } else {
                    // 判断是否为PDA设备
                    s isPDAExecution = 0
                    // 这里可以根据其他逻辑判断是否为PDA手动执行
                    // 例如：用户登录设备类型、请求来源等
                    i $d(^OEORD(+oeoreIdStr,"I",$p(oeoreIdStr,"||",2),"X",$p(oeoreIdStr,"||",3),"NUR")) {
                        s deviceType=$p($g(^OEORD(+oeoreIdStr,"I",$p(oeoreIdStr,"||",2),"X",$p(oeoreIdStr,"||",3),"NUR")),"^",26)
                        i deviceType=2 s isPDAExecution=1
                    }
                    i isPDAExecution s executeMethod=2  // PDA手动执行
                }
                
                s ^GRS("execOrder",userId_"-")=$lb(setSkinTest,oeoreIdStr,execStatusCode,userId,locId,sheetCode,$g(execDate),$g(execTime),$g(execReasonDr),$g(changeReasonDr),groupId,$g(auditUser),$g(isSttDateTime),"N",executeMethod)
                
                s retsult=##class(Nur.NIS.Service.Base.OrderHandle).UpdateOrdGroupChunks($g(setSkinTest),oeoreIdStr,execStatusCode,userId,locId,sheetCode,$g(execDate),$g(execTime),$g(execReasonDr),$g(changeReasonDr),groupId,$g(auditUser),$g(isSttDateTime),"N",executeMethod) 
                
                i retsult.GetAt("success") = 0 {
                    s length=$l(oeoreIdStr,"^")
	                f index=1:1:length {
                        s oeoreId=$p(oeoreIdStr,"^",index)
                        s parr="WorkIP|"_"^WorkPlace|PDA"_"^ScanFlag|"_scanFlag
                        d ##class(Nur.MNIS.IPExeWorkLoad).Save(parr,"", userId , locId, oeoreId, "PDA")
                        d ..SaveOrdExecExtInfo(oeoreId,execStatusCode,wardId,executeMethod) 
                    }
                } else {
                    s Msg=retsult.GetAt("errList").GetAt(1).GetAt("errInfo"), Status = "-1"
                } 
            }
        }
        s tBehavior="request" 
        s tRequest="GetOrdersV4&GetOrderTasksV4" // 刷新两个请求
    }
    
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    d json.SetAt($g(patInfo),"patInfo")
    d json.SetAt($g(userInfo),"userInfo")
    d json.SetAt($g(barcodeFlag),"barCodeType")
    d json.SetAt($g(newEntities),"entities")
    //behavior是行为控制-可以是多个","  ; request是请求那个方法名 例如:"GetOrdersV4" 或 "GetOrdersV4&GetOrderTasksV4"
    //例如1: behavior="open" 打开面板 "close" 关闭面板 "search" 刷新请求列表-->空即可d json.SetAt("","request")
    //例如2: behavior="request" 再调用"ExecOrSeeOrderV4"-->需要d json.SetAt("ExecOrSeeOrderV4","request")
    i $g(tBehavior)'="" d json.SetAt(tBehavior,"behavior")
    i $g(tRequest)'="" d json.SetAt(tRequest,"request")
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
    
errExecOrSeeOrderV4
   s Msg=$ze
   s ^GRS("errExecOrSeeOrderV4")=Msg
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 更新PDA设备标识
ClassMethod SaveOrdExecExtInfo(oeoreId, execStatusCode, wardId)
{
    n (oeoreId,execStatusCode,wardId)
    s $ZT="errorSave"
    s ret=0
    s execExtobj=##class(User.OEOrdExecExt).%OpenId(oeoreId)
    if $ISObject(execExtobj) {
        //设备标识: 1是PC 2是PDA
        i execStatusCode="F" s execExtobj.OEOREDeviceType=2 
        e  s execExtobj.OEOREDeviceType=""
        d execExtobj.%Save()
    }
    s child=0  
    f 
    {   
        s child=$o(^OEORDi(0,"OEORE",oeoreId,+oeoreId,child))
        q:child=""
        s childSub=0  
        f 
        {   s childSub=$o(^OEORDi(0,"OEORE",oeoreId,+oeoreId,child,childSub))
            q:childSub=""
            s childOrdId=+oeoreId_"||"_child_"||"_childSub
            s ret=..SaveOrdExecExtInfo(childOrdId,execStatusCode,wardId)
            s execExtobj=##class(User.OEOrdExecExt).%OpenId(childOrdId)
            if $ISObject(execExtobj) {
                i execStatusCode="F" s execExtobj.OEOREDeviceType=2
                e  s execExtobj.OEOREDeviceType=""
                d execExtobj.%Save()
            }
        }
    }
    q ret
errorSave
    s ret="-1"
    q ret
}

/// w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.ScanEvents).GetScanInfoV3("OrderExecute","scan","1174||1171||1","3","20665","8","23","2","[{""barcode"":""0000000689"",""entity"":""patient"",""manual"":""0"",""result"":""1708"",""scan"":""1""},{""barcode"":""1174||1169||1"",""entity"":""order"",""manual"":""0"",""result"":"""",""scan"":""1""}]",""))
ClassMethod GetScanInfoV3(module, motion, barcode, wardId, userId, locId, groupId, hospitalId, entities, extras)
{
    n (module,motion,barcode,wardId,userId,locId,groupId,hospitalId,entities,extras)
    s $zt="errGetScanInfoV3"
    s ^GRS("GetScanInfoV3")=$lb(module,motion,barcode,wardId,userId,locId,groupId,hospitalId,extras)
    s msg="成功",msgcode="999999",status="0" //定义初始值
    
    i entities="" s entities=##class(%ListOfDataTypes).%New()
    e  s entities=##class(Nur.MNISV3.Common.JSON).Decode(entities)
    
    
    s json=##class(%ArrayOfDataTypes).%New()
    s barcodeFlag=##class(Nur.MNISV3.Service.Barcode).GetBarcodeFlag(barcode,"","",wardId,.outputBarcode,.barcodeMessage,.ordFlag)
    s patInfo=##class(%ArrayOfDataTypes).%New()
    
    s dialog=##class(%ArrayOfDataTypes).%New()
    i barcodeFlag="PAT"
    {
        s barcode=outputBarcode // EH 如果腕带打印住院号
        s patinfoObj=##class(Nur.MNISV3.Common.JSON).Decode(##class(Nur.MNISV3.Service.Patient).GetPatWristInfo(barcode,wardId))
        s status=patinfoObj.GetAt("status")
        s msg=patinfoObj.GetAt("msg")
        s msgcode=patinfoObj.GetAt("msgcode")
        i status="0" 
        {
            s patInfo=patinfoObj.GetAt("patInfo")
            s patName=patInfo.GetAt("name")
            s bedCode=patInfo.GetAt("bedCode")
        }
        
        s buttons=##class(%ListOfDataTypes).%New()
        s button=##class(%ArrayOfDataTypes).%New()
        s text="确定"
        s request="GetOrdersV4"
        s behavior="request"
        d button.SetAt($g(autoClickTimeout),"autoClickTimeout")
        d button.SetAt($g(autoHideOnClick),"autoHideOnClick")
        d button.SetAt($g(backgroundColor),"backgroundColor")
        d button.SetAt($g(behavior),"behavior")
        d button.SetAt($g(callback),"callback")
        d button.SetAt($g(color),"color")
        d button.SetAt($g(disabled),"disabled")
        d button.SetAt($g(hidden),"hidden")
        d button.SetAt($g(icon),"icon")
        d button.SetAt($g(id),"id")
        d button.SetAt($g(motion),"motion")
        d button.SetAt($g(request),"request")
        d button.SetAt($g(text),"text")
        d buttons.Insert(button)
        
        s message=##class(%ArrayOfDataTypes).%New()
        s text=bedCode_" "_patName
        d message.SetAt($g(backgroundColor),"backgroundColor")
        d message.SetAt($g(checkbox),"checkbox")
        d message.SetAt($g(icon),"icon")
        d message.SetAt($g(radio),"radio")
        d message.SetAt($g(text),"text")
        d message.SetAt($g(textbox),"textbox")
        
        s title=##class(%ArrayOfDataTypes).%New()
        s text="患者信息"
        d title.SetAt($g(backgroundColor),"backgroundColor")
        d title.SetAt($g(text),"text")
        
        s dialog=##class(%ArrayOfDataTypes).%New()
        d dialog.SetAt($g(buttons),"buttons")
        d dialog.SetAt($g(message),"message")
        d dialog.SetAt($g(title),"title")
            
        s entitie="patient" 
        s scan=1
        s result="adm"
        s entities=##class(%ListOfDataTypes).%New()
        s entitie=##class(%ArrayOfDataTypes).%New()
        d entitie.SetAt($g(barcode),"barcode")
        d entitie.SetAt($g(entity),"entity")
        d entitie.SetAt($g(manual),"manual")
        d entitie.SetAt($g(result),"result")
        d entitie.SetAt($g(scan),"scan")
        d entities.Insert(entitie)
        s curDate=$zd(+$h,3)
        s curTime=$zt($p($h,",",2))
        //患者信息   
        d json.SetAt($g(Msg),"msg")
        d json.SetAt($g(msgcode),"msgcode")
        d json.SetAt($g(status),"status")
        d json.SetAt($g(patInfo),"patInfo")
        d json.SetAt($g(curDate),"curDate")
        d json.SetAt($g(curTime),"curTime")
        d json.SetAt($g(entities),"entities")
        d json.SetAt($g(dialog),"dialog")
    }else
    {
        s execFlag=1  //自动执行
        s panels=""
        s curDate=$zd(+$h,3)
        s curTime=$zt($p($h,",",2))
        s behavior="open"
        s panels=..GetOrderNodeInfo(barcode,hospitalId)
        w entities,!
        w entities.Count(),!
        //获取entities中的患者信息
        s episodeId=""
        f i=1:1:entities.Count()
        {
            s rowData=entities.GetAt(i)
            s entity=rowData.GetAt("entity")
            s barcodeEntity=rowData.GetAt("barcode")
            w barcodeEntity,!
            i entity="patient" s episodeId=+##class(Nur.MNISV3.Service.Patient).GetPatAdm(barcodeEntity)
            w episodeId,!
        }   
        w barcodeFlag,!
        //循环entities获取所有医嘱列表
        ///输液医嘱
        i barcodeFlag="INF" s orderInfo=..GetInfusionOrderItem(episodeId, barcode, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
        ///检验医嘱
        i barcodeFlag="LAB" s orderInfo=..GetLabOrderItem(episodeId, barcode, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
        ///口服药医嘱
        i barcodeFlag="MED" s orderInfo=..GetOralOrderItem(episodeId, barcode, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
        ///其他医嘱
        i barcodeFlag="PIS" s orderInfo=..GetOtherOrderItem(episodeId, barcode, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)    
        
        w orderInfo,!
        w ##class(Nur.JSON).Encode(orderInfo),!
        s orders=##class(%ListOfDataTypes).%New()
        d orders.Insert(orderInfo)
    
            
        f i=1:1:entities.Count()
        {
            s rowData=entities.GetAt(i)
            s entity=rowData.GetAt("entity")
            s barcodeEntity=rowData.GetAt("barcode")
            continue:entity="patient"
            
            ///输液医嘱
            i barcodeFlag="INF" s orderInfo=..GetInfusionOrderItem(episodeId, barcodeEntity, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
            ///检验医嘱
            i barcodeFlag="LAB" s orderInfo=..GetLabOrderItem(episodeId, barcodeEntity, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
            ///口服药医嘱
            i barcodeFlag="MED" s orderInfo=..GetOralOrderItem(episodeId, barcodeEntity, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)
            ///其他医嘱
            i barcodeFlag="PIS" s orderInfo=..GetOtherOrderItem(episodeId, barcodeEntity, wardId,userId,locId, .msg, .msgcode,.status,.execResult,execFlag,.patInfo)    
            i status="0" d orders.Insert(orderInfo)
        }
        s entity="Order"
        s entitie=##class(%ArrayOfDataTypes).%New()
        d entitie.SetAt($g(barcode),"barcode")
        d entitie.SetAt($g(entity),"entity")
        d entitie.SetAt($g(manual),"manual")
        d entitie.SetAt($g(result),"result")
        d entitie.SetAt($g(scan),"scan")
        d entities.Insert(entitie)
        
        
        d json.SetAt($g(patInfo),"patInfo")
        d json.SetAt($g(curDate),"curDate")
        d json.SetAt($g(curTime),"curTime")
        d json.SetAt($g(entities),"entities")
        d json.SetAt($g(behavior),"behavior")
        d json.SetAt($g(orders),"orders")
        d json.SetAt($g(panels),"panels")
        d json.SetAt($g(wayOrders),"wayOrders") 
    } 
    
    q json
    
errGetScanInfoV3
   s Msg=$ze
   q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// Creator:        JYW
/// CreatDate:      2018-08-20
/// Description:    获取输液医嘱信息
/// Input：          episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult
/// Return：     
/// Others：     
/// w ##class(Nur.MNIS.Service.ScanEvents).GetInfusionOrderItem("2","1||353||805","3","20665","8","成功","999999","0",0,1)
ClassMethod GetInfusionOrderItem(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult, execFlag, patInfo)
{
    n (episodeId,barcode,wardId,userId,userDeptId,msg,msgcode,status,execResult,execFlag,patInfo,%session)
    s ^zlf("GetInfusionOrderItem")=$lb(episodeId,barcode,wardId,userId,userDeptId,msg,msgcode,status,execResult,execFlag)
    //// 取所有的配置列
    s hospID=##class(Nur.MNIS.Service.Session).GetWardHospID(wardId)
    s Columns=##class(Nur.MNIS.Service.Order).GetColumns(hospID)
    s orderInfo=##class(%ArrayOfDataTypes).%New()
    s OrderList=##class(%ListOfDataTypes).%New()
    s admId=+^OEORD(+barcode)
    b
    i admId'=episodeId&&(episodeId'="") {s msg="不是该病人医嘱",msgcode="100324",status="-1"}
    else
    {
        
        s patInfo=##class(Nur.NIS.Service.Base.Patient).GetPatient(admId)
        s barcode=$replace(barcode,"||","-")
        s ord=+barcode
        s chl=$P(barcode,"-",2)
        s sub=$P(barcode,"-",3)
        s orderInfo=##class(Nur.MNIS.Service.Order).InitOrderInfo(ord,chl,sub,Columns)
        d OrderList.Insert(orderInfo)
        s childOrdInfo=##class(%ListOfDataTypes).%New()
        s mainOeoreID=ord_"||"_chl_"||"_sub
        i execFlag=0 s execResult=##class(Nur.MNIS.Service.Order).ExecOrder(mainOeoreID, "F", userId, userDeptId, wardId)
        s child=0  
        f 
        {   s child=$o(^OEORDi(0,"OEORE",mainOeoreID,ord,child))
            q:child=""
            s childSub=0  
            f 
            {   s childSub=$o(^OEORDi(0,"OEORE",mainOeoreID,ord,child,childSub))
                q:childSub=""
                s childOrdId=ord_"||"_child_"||"_childSub
                s arcimDr=$P($G(^OEORD(ord,"I",child,1)),"^",2)
                s itemCatDr=$P($G(^ARCIM(+arcimDr,$p(arcimDr,"||",2),1)),"^",10)
                s ordTyp=$P(^ARC("IC",itemCatDr),"^",7)
                continue:ordTyp'="R" //过滤掉非药品医嘱 
                s childorderInfo=##class(Nur.MNIS.Service.Order).InitOrderInfo(ord,child,childSub,Columns)
                d OrderList.Insert(childorderInfo)
            }
        }
        
     }
     q OrderList
}

/// Creator:        LMM
/// CreatDate:      2019-11-11
/// Description:    获取口服药医嘱信息
/// Input：          episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,barcodeFlag
/// Return：     
/// Others： 
/// w ##class(Nur.MNIS.Service.ScanEvents).GetMsgByOrd("","0000000885","3","10212",$c(0),"核对信息无误","999999","0","LAB","")
ClassMethod GetMsgByOrd(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, barcodeFlag, canExeFlag)
{
    n (episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status,barcodeFlag,canExeFlag)
    ;s ^MML("getMsgByOrd")=$lb(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status,barcodeFlag,canExeFlag)
    s str=""
    i barcodeFlag="MED"  s str=##class(Nur.MNIS.Service.ScanEvents).NurMnisGetBagID(barcode) //..GetMedOrd(barcode,wardId)  //##class(Nur.MedicineBagInfo).GetBagID(barcode)
    i barcodeFlag="LAB"  d
    .s Ord=""  f  s Ord=$O(^OEORD(0,"EpisNo",barcode,Ord)) q:Ord=""  d
    ..s chl=""  f  s chl=$O(^OEORD(0,"EpisNo",barcode,Ord,chl)) q:chl=""  d
    ...s ordStateDr=$P($G(^OEORD(Ord,"I",chl,1)),"^",13) //医嘱状态
    ...;q:ordStateDr'="1"
    ...s mainOeoreID=Ord_"||"_chl_"||1"
    ...s str=$s(str="":mainOeoreID,1:str_"^"_mainOeoreID)
    i barcodeFlag="INF"  s str="!"_$replace(barcode,"-","||")
    i barcodeFlag="PIS"  s str="!"_$replace(barcode,"-","||")
    s canExeFlag=0  //默认不能执行
    s num=$L(str,"^")
    k tmp("exeInfo")
    s dNum=0,fNum=0,uNum=0,dMsg="",fMsg="",uMsg=""
    f i=1:1:num 
    {
      s ordrow=$P(str,"^",i)
      continue:ordrow=""
      s ordrow=$tr(ordrow,"!","")
      s Ord=$P(ordrow,"||",1),chl=$P(ordrow,"||",2),sub=$P(ordrow,"||",3)
      i (sub="") s sub=1
      s admId=$P(^OEORD(+ordrow),"^",1) 
      i admId'=episodeId&&(episodeId'="") {
          i (barcodeFlag="MED")||(barcodeFlag="INF") s msg="不是该病人药品"
          i (barcodeFlag="LAB") s msg="不是该病人条码"
          s msgcode="10871",status="-1" q
      }    
      s exeInfo=##class(Nur.MNIS.Service.Order).GetExeStatusInfo(Ord,chl,sub)
      i $p(exeInfo,"^",1)="D" s dNum=dNum+1
      i $p(exeInfo,"^",1)="F" s fNum=fNum+1
      i $p(exeInfo,"^",1)="U" s uNum=uNum+1
      i ($p(exeInfo,"^",1)'="F")&&($p(exeInfo,"^",1)'="D")&&($p(exeInfo,"^",1)'="U") s canExeFlag=1
      //s xpxyFlag=##class(Nur.MNIS.Service.Order).GetXTXYFlag(ordrow)
    }
    i dNum'=0 s dMsg=dNum_"条已停止"
    i fNum'=0 s fMsg=fNum_"条已执行"
    i uNum'=0 s uMsg=uNum_"条已作废"
    i (dNum'=0)||(fNum'=0)||(uNum'=0) s msg="共"_num_"条医嘱,其中有:"_" "_$g(dMsg)_" "_$g(fMsg)_" "_$g(uMsg)
    i barcodeFlag="INF"&&(dNum'=0) s msg="<span style=""color:red"">医嘱已停止</span>"
    i barcodeFlag="INF"&&(fNum'=0) s msg="<span style=""color:red"">医嘱已执行</span>"
    i barcodeFlag="INF"&&(uNum'=0) s msg="<span style=""color:red"">医嘱已作废</span>"
    i barcodeFlag'="PAT"&&(num=0) s msg="<span style=""color:red"">没有可执行的医嘱</span>"
    //i $g(xpxyFlag)=2  s msg=msg_" (配液超过两个小时)"
    q msg
}

ClassMethod NurMnisGetBagID(medid As %String) As %String
{
     s OrdStr=""
      s date="" f  s date=$O(^Nur.MedicineBagInfoI("MedBag"," "_medid,date)) q:date=""  d
      .s tim=""  f  s tim=$O(^Nur.MedicineBagInfoI("MedBag"," "_medid,date,tim)) q:tim=""  d
      ..s Ord="" f  s Ord=$O(^Nur.MedicineBagInfoI("MedBag"," "_medid,date,tim,Ord)) q:Ord=""  d
      ...s rw=""  f  s rw=$O(^Nur.MedicineBagInfoI("MedBag"," "_medid,date,tim,Ord,rw)) q:rw=""  d
      ....//s a=##class(Nur.MedicineBagInfo).%OpenId(rw)
      ....s OrdNew=$tr(Ord," ","")
      ....s OrdStr=OrdStr_""_OrdNew_"^"
     
     q OrdStr
}

/// Creator:        JYW
/// CreatDate:      2018-08-20
/// Description:    获取口服药医嘱信息
/// Input：          episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult
/// Return：     
/// Others： 
/// w ##class(Nur.MNIS.Service.ScanEvents).GetOralOrderItem()
ClassMethod GetOralOrderItem(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult, execFlag)
{
    n (episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,execFlag,%session)
    s ^zlf("GetOralOrderItem")=$lb(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,execFlag)
    //s str=##class(Nur.MNIS.Service.ScanEvents).NurMnisGetBagID(barcode) 
    //s str=..GetMedOrd(barcode)  
    //s str=##class(Nur.MedicineBagInfo).GetBagID(barcode)
    s str=barcode
    s hospID=##class(Nur.MNIS.Service.Session).GetWardHospID(wardId)
    s Columns=##class(Nur.MNIS.Service.Order).GetColumns(hospID)
    s OrderList=##class(%ListOfDataTypes).%New()
    s num=$L(str,"^")
    f i=1:1:num 
    {
      s ordrow=$P(str,"^",i)
      q:ordrow=""
      s Ord=$P(ordrow,"||",1),chl=$P(ordrow,"||",2),sub=$P(ordrow,"||",3)
      s admId=$P(^OEORD(+ordrow),"^",1) 
      i admId'=episodeId&&(episodeId'="") s msg="不是该病人药品",msgcode="10871",status="-1" q
      i execFlag=0 s execResult=##class(Nur.MNIS.Service.Order).ExecOrder(ordrow, "F", userId, userDeptId, wardId)
      s orderInfo=##class(Nur.MNIS.Service.Order).InitOrderInfo(Ord,chl,sub,Columns)
      d OrderList.Insert(orderInfo)
    
    }
    q $G(OrderList)
}

/// Creator:        JYW
/// CreatDate:      2018-08-20
/// Description:    获取检验医嘱信息
/// Input：          episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult
/// Return：     
/// Others： 
/// w ##class(Nur.MNIS.Service.ScanEvents).GetLabOrderItem()
ClassMethod GetLabOrderItem(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult, execFlag)
{
    n (episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,execFlag,%session)
    ;s ^LMS("getLabOrderItem")=$LB(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,execFlag)
    s OrderList=##class(%ListOfDataTypes).%New()
    s hospID=##class(Nur.MNIS.Service.Session).GetWardHospID(wardId)
    s Columns=##class(Nur.MNIS.Service.Order).GetColumns(hospID)
    s Ord=""  f  s Ord=$O(^OEORD(0,"EpisNo",barcode,Ord)) q:Ord=""  d
    .s admId=$P(^OEORD(Ord),"^",1)
    .i admId'=episodeId&&(episodeId'="") s msg="不是这个病人的医嘱",msgcode="100521",status="-1" q
    .e  d
    ..ts
    ..s chl=""  f  s chl=$O(^OEORD(0,"EpisNo",barcode,Ord,chl)) q:chl=""  d
    ...s ordStateDr=$P($G(^OEORD(Ord,"I",chl,1)),"^",13) //医嘱状态
    ...;q:ordStateDr'="1"
    ...s mainOeoreID=Ord_"||"_chl_"||1"
    ...i (execFlag=0)&&(success=1)&&("^1^6^"[ordStateDr) d
    ....s execResult=##class(Nur.MNIS.Service.Order).ExecOrder(mainOeoreID, "F", userId, userDeptId, wardId)
    ....//i execResult=0 d ##class(web.DHCNurSpecerNo).UpdateSpacer(mainOeoreID,userId) //更新采血时间
    ....i (execResult'=0) s msg=execResult,msgcode="100521",status="-1" q
    ...s Info=##class(Nur.MNIS.Service.Order).InitOrderInfo(Ord,chl,1,Columns)
    ...d OrderList.Insert(Info)
    ..i (status="-1") tro
    ..e  tc
    q $G(OrderList)
}

ClassMethod GetOtherOrderItem(episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult, execFlag)
{
    n (episodeId, barcode, wardId, userId, userDeptId, msg, msgcode, status, execResult,execFlag,%session)
    s str=$replace(barcode,"-","||")
    s hospID=##class(Nur.MNIS.Service.Session).GetWardHospID(wardId)
    s Columns=##class(Nur.MNIS.Service.Order).GetColumns(hospID)
    s OrderList=##class(%ListOfDataTypes).%New()
    s num=$L(str,"^")
    f i=1:1:num 
    {
      s ordrow=$P(str,"^",i)
      q:ordrow=""
      s Ord=$P(ordrow,"||",1),chl=$P(ordrow,"||",2),sub=$P(ordrow,"||",3)
      i (sub="") s sub=1
      s admId=$P(^OEORD(+ordrow),"^",1) 
      i admId'=episodeId&&(episodeId'="") s msg="不是该病人医嘱",msgcode="10871",status="-1" q
      i execFlag=0 s execResult=##class(Nur.MNIS.Service.Order).ExecOrder(ordrow, "F", userId, userDeptId, wardId)
      s orderInfo=##class(Nur.MNIS.Service.Order).InitOrderInfo(Ord,chl,sub,Columns)
      d OrderList.Insert(orderInfo)
    
    }
    q $G(OrderList)
}

/// w ##class(Nur.MNISV3.Service.ScanEvents).GetBarCodeType(barcode,hospitalId,locId,wardId)
ClassMethod GetBarCodeType(barcode, hospitalId, locId, wardId)
{
    n (barcode,hospitalId,locId,wardId)
    s $zt="errGetBarCodeType"
    s msg="成功",msgcode="999999",Status="0"
    s barcodeType=""
    i barcode["SYNO" s barcodeType="DEV",barcodeDesc="输液设备"

    s json=##class(%ArrayOfDataTypes).%New()
    d json.SetAt($g(msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    d json.SetAt($g(barcodeFlag),"barcodeType")
    d json.SetAt($g(barcodeDesc),"barcodeDesc")
    q json   
errGetBarCodeType
    s msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(msg,"102231","-1")
}

/// w ##class(Nur.MNISV3.Service.ScanEvents).GetOrderNodeInfo("1174||1171||1")
ClassMethod GetOrderNodeInfo(oeordId, hospitalId)
{
    n (oeordId,hospitalId,%session)
    
    //获取当前节点
    s curnode=""
    s date=""
    f 
    {
        s date=$o(^Nur.MNISV3.NodeHandleRecI("OeoreDate"," "_oeordId,date),-1)
        q:date=""
        s time=""
        f
        {
            s time=$o(^Nur.MNISV3.NodeHandleRecI("OeoreDate"," "_oeordId,date,time),-1)
            q:time=""
            s node=""
            f
            {
                s node=$o(^Nur.MNISV3.NodeHandleRecI("OeoreDate"," "_oeordId,date,time,node),-1)
                q:node=""||(curnode'="")
                s curnode=node  
            }
        }
    }
    w curnode,!
    s curnode=$replace(curnode," ","")
    s nodeType="INFORD"  //测试阶段先用输液，后续需要判断闭环类型
    i curnode="" s curnode="DINFORD"
    
    //模板配置
    s modelList=##class(Nur.MNISV3.Service.Blood).GetModelInfoByStatus(curnode,hospitalId,nodeType)
 
    //节点状态
    s nodeListObj=##class(Nur.MNISV3.Service.Blood).GetNodeList(hospitalId,nodeType,curnode)
    s nodeStatusList=nodeListObj.GetAt("nodeList")
   
    //按钮（即可操作节点）
    s buttonListObj=##class(Nur.MNISV3.Service.Blood).GetButtonList(hospitalId,nodeType,curnode)
    s buttonList=buttonListObj.GetAt("nodeList")

    
    //默认走一个页签   多个按钮
    s panels=##class(%ListOfDataTypes).%New()
    s panel=##class(%ArrayOfDataTypes).%New()
    d panel.SetAt(buttonList,"buttons")
    d panel.SetAt(modelList,"modelList")
    d panel.SetAt(nodeStatusList,"nodeStatusList")
    d panel.SetAt("","selected")
    d panel.SetAt("操作描述","title")
    d panel.SetAt("","id")
    d panels.Insert(panel)
    q panels
}

/// 创建一个Dialog
/// w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.Order).CreateDialog("提示","是否复制该护理问题?","确定","copy","取消","outcome"))
ClassMethod CreateDialog(mTitle = "提示", message = "", okText = "确定", okBehavior = "", okRequest = "", cancelText = "取消", cancelBehavior = "cancel")
{
    n (mTitle,message,okText,okBehavior,okRequest,cancelText,cancelBehavior)
    s title=..CreateObject("text,backgroundColor",mTitle,"") 
    s message=..CreateObject("text,backgroundColor",message,"#DBECFF") 
    s buttons=##class(%ListOfDataTypes).%New() 
    //剩余 CallbackBean callback;String motion; String autoClickTimeout; String autoHideOnClick;
    d buttons.Insert(..CreateObject("text,behavior,request,backgroundColor,color,disabled",okText,okBehavior,okRequest))
    d buttons.Insert(..CreateObject("text,behavior,backgroundColor,color,disabled",cancelText,cancelBehavior))
   
    s dialog=##class(%ArrayOfDataTypes).%New()
    d dialog.SetAt($g(message),"message") //MessageBean
    d dialog.SetAt($g(title),"title") //TitleBean
    d dialog.SetAt($g(buttons),"buttons") //List<ButtonsBean>
    q dialog
}

/// 快速创建一个对象， 第一个参数“,”分割 和后面args顺序对应
/// 测试: w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.Order).CreateObject("name,age","张三","18")) 
ClassMethod CreateObject(keys, args...) As %String [ Internal ]
{
    n (keys,args)
    s obj= ##class(%ArrayOfDataTypes).%New() 
    s ks=$replace(keys,"^",",") ;替换,分割符
    ;转换成 $lb("name","age")  语法：$listfromstring() 将分隔符字符串转换为列表
    s lb=$lfs(ks,","),len=$ll(lb)
    f i=1:1:len {
        s key=$lg(lb,i)  ;w $lg(lb,i) -->依次取出 name  age
        continue:(key="")
        ; 这种格式: args=2 
        ;    args(1)="张三"
        ;    args(2)=18
        s value=$g(args(i)) 
        d obj.SetAt(value,key)
    }
    q obj
}

/// 通过节点CODE获取模板信息
/// w ##class(Nur.MNISV3.Service.ScanEvents).GetModelInfoByStatus("RECEIVE","2")
ClassMethod GetModelInfoByStatus(nodeCode, hospitalId)
{
    n (nodeCode,hospitalId)
    s ^GRS("GetModelInfoByStatus")=$lb(nodeCode,hospitalId)
    // 输血状态--处于那个节点  例如：^CF.NUR.MNISV3.BloodNodeI("Code"," 2"," BLOOD"," D",1)=""
    s nodeId=$o(^CF.NUR.MNISV3.NodeI("Code"," "_hospitalId," "_nodeCode,""))
    q:nodeId="" ""
    s nodeObj=##class(CF.NUR.MNISV3.Node).%OpenId(nodeId)
    s showModelCode=nodeObj.ModelCode //显示模板Code
    s nodeSub=nodeObj.NextNodes       //可操作节点Code 用!分隔
    s nodeCode=nodeObj.NodeCode
    s SignFlag=nodeObj.SignFlag
    d nodeObj.%Close()
    w showModelCode_"-"_nodeSub,!
    s ^GRS("GetModelInfoByStatus111")=$lb(showModelCode,nodeSub)
    s modelList=##class(%ListOfDataTypes).%New()
    i showModelCode'=""{ //优先取showModelCode
        s modelInfo=..GetModelInfoByModeCode(showModelCode,hospitalId)
        d modelInfo.SetAt($g(nodeCode),"ModelCode")
        d modelInfo.SetAt($g(SignFlag),"SignFlag")  //(loginDouble 双签 loginSingle/空 单签  double 双签  single 单签) LD LS D S
        d modelList.Insert(modelInfo)
    }else{
        f i=1:1:$l(nodeSub,"!") //遍历可操作节点
        {
            s nodeCode=$p(nodeSub,"!",i)
            continue:nodeCode=""
            s nodeId=$o(^CF.NUR.MNISV3.NodeI("Code"," "_hospitalId," "_nodeCode,""))
            continue:nodeId=""
            s nodeObj=##class(CF.NUR.MNISV3.BloodNode).%OpenId(nodeId)
            s nodeName=nodeObj.NodeName
            s ModelCode=nodeObj.ModelCode
            s SignFlag=nodeObj.SignFlag
            d nodeObj.%Close()
            w "nodeName="_nodeName_"ModelCode="_ModelCode,!
            s modelInfo=..GetModelInfoByModeCode(ModelCode,hospitalId)
            d modelInfo.SetAt($g(nodeCode),"ModelCode")
            d modelInfo.SetAt($g(nodeName),"ModelName")
            d modelInfo.SetAt($g(SignFlag),"SignFlag")
            d modelList.Insert(modelInfo)            
        }
    }
    //w ##class(Nur.MNISV3.Common.JSON).Encode(modelInfo),!
    w ##class(Nur.MNISV3.Common.JSON).Encode(modelList),!
    q modelList
}

/// 通过模板代码获取模板信息
/// w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.Blood).GetModelInfoByModeCode("PATINFO!BLOODINFO","2"))
ClassMethod GetModelInfoByModeCode(modeCode, hospitalId)
{
    n (modeCode,hospitalId)
    s ^GRS("GetModelInfoByModeCode")=$lb(modeCode,hospitalId)
    s formList=##class(%ListOfDataTypes).%New() 
    s subId=""
    f i=1:1:$l(modeCode,"!") //遍历可操作节点
    {
        s formCode=$p(modeCode,"!",i)
        continue:formCode=""
        s formCode=$ZCVT(formCode,"U") //Form组件索引
        s formId=$o(^CF.NUR.MNISV3.ModelFormI("Code"," "_hospitalId," "_formCode,""))
        continue:formId=""
        //w "formId="_formId,!
        s formData=##class(%ArrayOfDataTypes).%New()
        s itemList=##class(%ListOfDataTypes).%New() 
        s itemId=""
        f 
        {
            s itemId=$o(^CF.NUR.MNISV3.ModelItemD(formId,itemId)) //遍历Item配置
            q:itemId=""
            //w "itemId="_formId_"||"_itemId,!
            s itemObj=##class(CF.NUR.MNISV3.ModelItem).%OpenId(formId_"||"_itemId) 
            s position=itemObj.Position
            s itemData=##class(%ArrayOfDataTypes).%New()
            d itemData.SetAt(itemObj.ItemName,"ItemName")
            d itemData.SetAt(itemObj.ItemCode,"ItemCode")
            d itemData.SetAt(itemObj.ItemType,"ItemType")
            d itemData.SetAt(itemObj.ItemNote,"ItemNote")
            d itemData.SetAt(itemObj.ItemSort,"ItemSort")
            //位置 1,2 是第一行 第二列
            d itemData.SetAt(itemObj.Position,"Position")
            //宽度 0.5 屏幕宽度一半
            d itemData.SetAt(itemObj.ItemWidth,"ItemWidth")
            d itemData.SetAt(itemObj.LinkCode,"LinkCode")
            d itemData.SetAt(itemObj.LabelFlag,"LabelFlag")
            d itemData.SetAt(itemObj.SignCode,"SignCode")
            d itemData.SetAt(itemObj.RequiredFlag,"RequiredFlag")
            //对于Android类型: 文本TYPE_CLASS_TEXT=1; 数字TYPE_CLASS_NUMBER=2; TYPE_NUMBER_FLAG_DECIMAL=2000
            d itemData.SetAt(itemObj.KeyboardType,"KeyboardType")
            d itemData.SetAt(itemObj.SimpleFlag,"SimpleFlag")
            d itemData.SetAt(itemObj.DataSource,"DataSource")
            d itemData.SetAt(itemObj.ItemOption,"ItemOption")
            d itemData.SetAt(itemObj.ItemDefault,"ItemDefault")
            //是否能编辑  
            d itemData.SetAt(itemObj.CanEditFlag,"CanEditFlag")
            d itemData.SetAt(formId_"||"_itemId,"itemId")             
            d itemObj.%Close()
            d itemList.Insert(itemData) //插入items
        }
        s fromObj=##class(CF.NUR.MNISV3.ModelForm).%OpenId(formId)
        s FormCode=fromObj.FormCode
        s FormName=fromObj.FormName
        s FormSort=fromObj.FormSort
        s LabelFlag=fromObj.LabelFlag
        s SimpleFlag=fromObj.SimpleFlag 
        d fromObj.%Close()
        d formData.SetAt($g(itemList),"itemList")
        d formData.SetAt($g(FormCode),"FormCode")
        d formData.SetAt($g(FormName),"FormName")
        //显示类型
        s FormType=""
        i ($g(FormCode)="PATINFO")||($g(FormCode)="BLOODINFO") s FormType="1"
        d formData.SetAt($g(FormType),"FormType")
        d formData.SetAt($g(LabelFlag),"LabelFlag")
        d formData.SetAt($g(SimpleFlag),"SimpleFlag")
        d formList.Insert(formData) //插入form
    
    }
    s modelInfo=##class(%ArrayOfDataTypes).%New()
    d modelInfo.SetAt($g(formList),"formList")
    q modelInfo
}

}
